import { defineStore } from 'pinia'
import { createUUId } from '@/utils';
import { defaultAttrList } from '@/mock';
import { cloneDeep } from 'lodash-es';

// 初始化默认属性
const initAttrStore = () => {
  const attrs = cloneDeep(defaultAttrList)
  attrs.forEach((item) => {
    item.attrId = createUUId()
    item.attrValues.forEach((it) => {
      it.valueId = createUUId()
    })
  })
  return attrs
}

// 商品属性 提供默认值
export const useAttrsStore = defineStore({
  id: 'attrs',
  state: () => ({
    attrList: initAttrStore()
  }),
})
